package com.zhuoshi.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuoshi.entity.Client;
import com.zhuoshi.entity.ClientCustom;
import com.zhuoshi.entity.ClientExample;
import com.zhuoshi.entity.ClientExample.Criteria;
import com.zhuoshi.mapper.ClientCustomMapper;
import com.zhuoshi.mapper.ClientMapper;
import com.zhuoshi.service.ClientService;

@Service
public class ClientServiceImpl implements ClientService{
	
	@Autowired
	private ClientCustomMapper clientCustomMapper;
	
	@Autowired
	private ClientMapper clientMapper;

	@Override
	public List<ClientCustom> showClient(ClientCustom clientCustom) {
		// TODO Auto-generated method stub
		return clientCustomMapper.showClient(clientCustom);
	}

	@Override
	public void addClient(ClientCustom clientCustom) {		
		clientCustom.setClientid(UUID.randomUUID().toString());
		clientMapper.insertSelective(clientCustom);
	}

	@Override
	public Map showClient() {
		List<Client> lists = clientMapper.selectByExample(null);
		Map<Integer,String> map = new HashMap();
		for (Client client : lists) {
			map.put(client.getId(), client.getClientidname());
		}
		return map;
	}

	@Override
	public String selectNameById(Integer id) {
		Client client = clientMapper.selectByPrimaryKey(id);
		return client.getClientidname();
	}

	@Override
	public Integer selectIdByName(String name) {
		ClientExample clientExample = new ClientExample();
		Criteria createCriteria = clientExample.createCriteria();
		createCriteria.andClientidnameEqualTo(name);
		List<Client> clients = clientMapper.selectByExample(clientExample);
		return clients.get(0).getId();
	}
	

}

